Singly Linked List

Collection of interconnected nodes

SNode, which implements Position: 1) element; 2) next
Moving from one node to another <=> link hopping

2 special nodes: head and tail (next pointer equals null)

Plan:
1. Create the position interface: T getElement()
2. Create SNode as a class implementing the Position interface
3. Create EmptyListException class
4. Create SList<T> ADT:
int size()
boolean isEmpty()

void insertAtHead(T element)
void insertAtTail(T element)

T removeFromHead() throws EmptyListException
T removeFromTail() throws EmptyListException // O(n)

T getHead() throws EmptyListException
T getTail() throws EmptyListException

5. Create SinglyLinkedList as a class implementing the SList ADT



 head      tail
 2 -> 3 -> 4 -> null 5 -> null

- LeetCode: reverse linked list










6. Use the SinglyLinkedList class to realize a stack data structure


